<%--
  Created by IntelliJ IDEA.
  User: Lt
  Date: 2018/5/17
  Time: 22:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<title>促销管理 - 卡卷类型</title>

<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jquery-ui/jquery-ui.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jqgrid/ui.jqgrid.css"/>
<%--<jsp:include page="../../head.jsp"/>--%>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${contextPath}/static/statistics/js/vue.js"></script>
<script src=${contextPath}/static/layer/layui.all.js></script>
<script src="${contextPath}/static/countjs/regularYz.js"></script>
<!-- form表单处理 -->
<script type="text/javascript" src="${contextPath}/static/franchisee/form.js"></script>



<style type="text/css">
    .customBtn {
        line-height: 20px;
        margin-bottom: 3px;
    }

    .btnLine {
        margin-left: 1px;
        margin-top: 8px;
        margin-bottom: 2px;
    }

    @-webkit-keyframes bouncedelay {
        0%, 80%, 100% {
            -webkit-transform: scale(0.0)
        }
        40% {
            -webkit-transform: scale(1.0)
        }
    }

    @keyframes bouncedelay {
        0%, 80%, 100% {
            transform: scale(0.0);
            -webkit-transform: scale(0.0);
        }
        40% {
            transform: scale(1.0);
            -webkit-transform: scale(1.0);
        }
    }

    .autocomplete-suggestions {
        border: 1px solid #999;
        background: #FFF;
        overflow: auto;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestions strong {
        font-weight: normal;
        color: #3399FF;
    }

    @-moz-document url-prefix() {
        fieldset {
            display: table-cell;
        }
    }

    .ui-jqgrid .ui-priority-secondary{
        background: #d5effc;
    }

    .ui-jqgrid .ui-jqgrid-title{font-size:12px;}    /*修改grid标题的字体大小*/

    .ui-jqgrid-sortable {font-size:12px;}   /*修改列名的字体大小*/

    .ui-jqgrid tr.jqgrow td {font-size:12px; font-family:"宋体"} /*修改表格内容字体*/

    /*****  表头样式  ******/
    /*.ui-jqgrid .ui-jqgrid-titlebar{*/
    /*background-color: #878787;*/
    /*height: 36px;*/
    /*}*/
    /*****  标题样式  ******/
    .ui-jqgrid-sortable {
        text-align: center;
    }

    #cb_grid-coupontype-table{
        margin-left: 9px;
    }
    #grid-coupontype-table_rn {
        width: 36px;
    }

    #myModal .modal-body table tr{
        height: 30px;
    }
    #myModal .modal-body table input[type='text']{
        height: 22px;
    }
    #myModal .modal-body table select {
        height: 22px;
    }

    .popover-content{
        color: red;
    }
</style>

<div class="row" id="appAlert">
    <div class="row btnLine">
        <div class="button-len col-sm-12">
            <div style="width: 100%; margin-bottom: 10px;">
                <button class="btn btn-white btn-sm btn-purple customBtn"  id="addCoupon">
                    <i class="ace-icon fa fa-plus-circle purple"></i> 新增
                </button>
                <button class="btn btn-white btn-info btn-sm customBtn" id="editCoupon">
                    <i class="ace-icon fa fa-pencil blue"></i> 修改
                </button>
            </div>
            <input class="input-sm" type="text" id="keyword" style="margin-left: 0px;" value=""
                   placeholder="关键字">
            <button class="btn btn-sm btn-white btn-info search-len customBtn"
                    onclick="searchShop()">
                <i class="ace-icon fa fa-search orange"></i>搜索
            </button>
        </div>
    </div>
    <!-- 内容数据开始 -->
    <div class="col-xs-12" style="text-align: center;">
        <table id="grid-coupontype-table"></table>

        <div id="grid-coupontype-pager"></div>

    </div>

    <!-- 内容数据结束 -->

    <!-- 新增模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="">
            <div class="modal-content">
                <div class="modal-header" style="font-size: 20px; margin-bottom: -15px;">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">
                        卡卷 - <span id="alertTitle">新增</span>
                        <small id="smallTitle" class="hide" style="color: red; float: right; margin-top: 10px;"></small>
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <form method='post' class="demoform" id="punishformID">
                            <table class="" border="0" cellpadding="0" cellspacing="3" style="border: 1px solid #ccc; padding: 10px 5px;">
                                <tbody>
                                <tr>

                                    <td align="right" style="width: 70px">编号：
                                    </td>
                                    <td>
                                        <input name="id" type="text" value="" maxlength="" id="id" class="textBoxSheetNo hide" style="width:140px;">
                                        <input name="cardNo" type="text" value="" maxlength="10" id="cardNo" class="textBoxSheetNo" style="width:140px;" placeholder="" data-container="body" data-toggle="popover" data-placement="right" data-content="顶部的 Popover 中的一些内容" datatype="s5-16" errormsg="昵称至少5个字符,最多16个字符！" >
                                    </td>
                                    <td align="right" style="width: 80px">发放状态：
                                    </td>
                                    <td>
                                        <select name="state" id="state" style="width:135px;">
                                            <option selected="selected" value="1">正常</option>
                                            <option value="0">停止</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">名称：
                                    </td>
                                    <td colspan="3">
                                        <input name="cardName" type="text" maxlength="25" id="cardName" class="textBoxSheetNo" style="width:410px;" _value="" data-container="body" data-toggle="popover" data-placement="right" data-content="顶部的 Popover 中的一些内容">
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">券类别：</td>
                                    <td colspan="3">
                                        <select name="cardCategory" id="cardCategory" style="height:22px;width:198px;" _value="00">
                                            <%--<option selected="selected" value="00">默认类别</option>--%>
                                            <option selected="selected" value="1">实体门店</option>
                                            <option value="2">现上电商</option>
                                        </select>
                                    </td>

                                </tr>
                                <tr>
                                    <td align="right">券类型：
                                    </td>
                                    <td style="width: 195px;">
                                        <select name="cardType" id="cardType" style="width:70px; float: left" value="0">
                                            <option selected="selected" value="1">折扣卷</option>
                                            <option value="2">满减卷</option>
                                            <option value="3">兑换卷</option>

                                        </select>
                                        <input name="cardPrice" type="text" value="0.00" id="cardPrice" class="textBoxSheetNo hide" style="width:50px;  float: left; margin-left: 5px;" placeholder="0.00"  data-container="body" data-toggle="popover" data-placement="right" data-content="顶部的 Popover 中的一些内容">
                                        <span id="yy" class="hide">元</span>
                                        <label id="discountLa" class="" style=" margin-left: 5px; float:left;"> 折扣率：</label>
                                        <input name="discount" type="text" value="0.00" id="discount" class="textBoxSheetNo" style="width:50px; float: left" placeholder="0.00"  data-container="body" data-toggle="popover" data-placement="right" data-content="顶部的 Popover 中的一些内容">
                                    </td>
                                    <td align="right">预发数量：
                                    </td>
                                    <td>
                                        <input name="totalQuantity" type="text" value="0" maxlength="7" id="totalQuantity" class="textBoxSheetNo" style="width:50px;" _value="0"> 张（0表示不限制）
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">有效期：
                                    </td>
                                    <td colspan="3">
                                        <fieldset id="fieldYXQ" style="width: 405px">
                                            <table id="tableYXQ" border="0" cellpadding="0" cellspacing="3">
                                                <tbody>
                                                <tr>
                                                    <td>
                                                        <input value="radDate" name="ctl00$MPContent$" type="radio" id="ctl00_MPContent_radDate" checked="checked" value="true"> 从
                                                    </td>
                                                    <td>

                                                        <table cellspacing="0" cellpadding="0">
                                                            <tbody>
                                                            <tr>
                                                                <td>
                                                                    <input name="beginTime" type="text" id="beginTime" class="TextBox" style="width:156px;" size="94" value="" placeholder="开始时间">
                                                                </td>
                                                                <td id="ctl00_MPContent_txtBeginAndEnd_tdEnd">
                                                                    &nbsp;&nbsp;至&nbsp;&nbsp;
                                                                    <input name="endTime" type="text" id="endTime" class="TextBox" style="width:156px;" size="93" value="" placeholder="结束时间">
                                                                </td>

                                                            </tr>
                                                            </tbody>
                                                        </table>

                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <input value="radDay" name="ctl00$MPContent$" type="radio" id="ctl00_MPContent_radDay" _value="false"> 从发放日第
                                                        <input name="beginNoDay" type="text" value="0" id="beginNoDay" class="textBoxSheetNo" style="width:65px;" value="0"> 日起，
                                                        <input name="validDays" type="text" value="0" id="validDays" class="textBoxSheetNo" style="width:65px;" value="0"> 内有效
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">使用日：
                                    </td>
                                    <td colspan="3">
                                        <input id="ctl00_MPContent_chkMonday" type="checkbox" name="ctl00$MPContent$chkMonday" checked="checked" _value="true"><label for="ctl00_MPContent_chkMonday">一</label>
                                        <input id="ctl00_MPContent_chkTuesday" type="checkbox" name="ctl00$MPContent$chkTuesday" checked="checked" _value="true"><label for="ctl00_MPContent_chkTuesday">二</label>
                                        <input id="ctl00_MPContent_chkWednesday" type="checkbox" name="ctl00$MPContent$chkWednesday" checked="checked" _value="true"><label for="ctl00_MPContent_chkWednesday">三</label>
                                        <input id="ctl00_MPContent_chkThursday" type="checkbox" name="ctl00$MPContent$chkThursday" checked="checked" _value="true"><label for="ctl00_MPContent_chkThursday">四</label>
                                        <input id="ctl00_MPContent_chkFriday" type="checkbox" name="ctl00$MPContent$chkFriday" checked="checked" _value="true"><label for="ctl00_MPContent_chkFriday">五</label>
                                        <input id="ctl00_MPContent_chkSaturday" type="checkbox" name="ctl00$MPContent$chkSaturday" checked="checked" _value="true"><label for="ctl00_MPContent_chkSaturday">六</label>
                                        <input id="ctl00_MPContent_chkSunday" type="checkbox" name="ctl00$MPContent$chkSunday" checked="checked" _value="true"><label for="ctl00_MPContent_chkSunday">日</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" style="width: 74px;">使用限制：
                                    </td>
                                    <td colspan="3">
                                        <fieldset id="fieldHYXZ" style="width: 405px">
                                            <table id="tableHYXZ" cellspacing="3">
                                                <tbody>
                                                <tr>
                                                    <td>每人每日限用<input name="dayUseLinit" type="text" value="0" maxlength="4" id="dayUseLinit" class="textBoxSheetNo" style="width:70px;" value="0">张（0表示不限制）
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>每人每日限领<input name="dayGetLinit" type="text" value="0" maxlength="4" id="dayGetLinit" class="textBoxSheetNo"  style="width:70px;" value="0">张（0表示不限制）
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>每人总共限领<input name="userLinit" type="text" value="0" maxlength="4" id="userLinit" class="textBoxSheetNo" style="width:70px;" _value="0">张（0表示不限制）
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>同一单可使用<input name="orderUseLinit" type="text" value="0" maxlength="4" id="orderUseLinit" class="textBoxSheetNo" style="width:70px;" _value="0">张（0表示不限制）
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </fieldset>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">最低消费：
                                    </td>
                                    <td colspan="3">消费指定范围内的商品满<input name="minUseAmt" type="text" value="0.00" id="minUseAmt" class="textBoxSheetNo" style="width:80px;" _value="0.00">元可使用（0表示不限制，不勾选"限定使用商品范围"则默认全场）
                                    </td>
                                </tr>

                                <%--<tr id="trUseServal">--%>
                                <%--<td align="right">使用数量：--%>
                                <%--</td>--%>
                                <%--<td colspan="3">同一单可使用<input name="ctl00$MPContent$txtUseServalGiftCertificate" type="text" value="0" maxlength="4" id="ctl00_MPContent_txtUseServalGiftCertificate" class="textBoxSheetNo" onblur=" if(checkObject(this,2)){return false;}" style="width:70px;" _value="0">张（0表示不限制）--%>
                                <%--</td>--%>
                                <%--</tr>--%>

                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-default btn-xs" data-dismiss="modal" v-on:click="close">关闭</button>
                    <button type="button" class="btn btn-primary btn-xs" v-on:click="saveCoupon">提交更改</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>

</div>

<input type="text" name="fileStr" id="fileStr" style="display:none"/>
<input type="text" name="fileType" id="fileType" style="display:none"/>

<!-- page specific plugin scripts -->
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
<!-- 公用变量 -->
<script type="text/javascript">

    var grid_coupontype_selector = "#grid-coupontype-table";
    var pager_coupontype_selector = "#grid-coupontype-pager";

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

    var img64 = "";

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

    var queryModel = {
        //分页参数
        page: '1',
        rows: '10',
    }

    $("#id").show();
    $("#showImageInfoImg").attr("src", img64);
    $("#showImageInfoImg1").attr("src", img64);

</script>

<!-- Vue实现 -->
<script type="text/javascript">
    var app = new Vue({
        el: '#appAlert',
        data: {
            objects: [],
        },
        methods: {
            saveCoupon: function () {
                getObjects()
            },
        }
    });
</script>

<!-- 方法调用 -->
<script type="text/javascript">
    var getObjects = function () {
        var obj = $("#punishformID").serializeJson();
        console.log($(".popover-content").html())
        if ($(".popover-content").html()){
            layer.msg("提示：请检查您的数据！")
            return
        }
        if($("#cardNo").val() == ''){
            layer.msg("提示：编号不能为空！")
            return
        }

        if($("#cardName").val() == ''){
            layer.msg("提示：名称不能为空！")
            return
        }
        if ($("#cardType").val() == ''){
            layer.msg("提示：卡卷类型不能为空！")
            return
        }
        if($("#cardType").val() == '1'){
            console.log($("discount").val());
            if($("discount").val() <= 0){
                layer.msg("提示：折扣率必须大余0")
                return
            }
        }else {
            if($("cardPrice").val() <= 0){
                layer.msg("提示：价格必须大余0")
                return
            }
        }
        console.log(obj)
        layer.load(1)
        $.ajax({
            url: '${contextPath}/ktSaleProject/saveCardProd',
            type: 'post',
            data: obj,
            success: function (data) {
                layer.closeAll('loading');
                if (data.success == false){
                    layer.msg("获取出错："+data.message)
                    return
                }
//                var dataArray = data.data;
//                if (dataArray.length == 0){
//                    layer.msg("查询没有数据")
//                    return
//                }

                $('#myModal').modal('hide');
                layer.msg("提示："+data.message);
                reload();
            },
            error: function (error) {
                layer.closeAll('loading')
            }
        })
    };

    /************ 时间插件 ************/
    $('#beginTime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd HH:mm:ss",
//        startDate:new Date(),
    });

    $('#endTime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd HH:mm:ss",
//        startDate:new Date(),
    });
    /*********************************/

    $("#cardType").change(function () {
        var cardType = $(this).val();
        if (cardType == '1'){
            $("#yy").addClass('hide');
            $("#cardPrice").addClass('hide');
            $("#discountLa").removeClass('hide');
            $("#discount").removeClass('hide');
        }
        if (cardType == '2'){
            $("#cardPrice").removeClass('hide');
            $("#yy").removeClass('hide');
            $("#discountLa").addClass('hide');
            $("#discount").addClass('hide');
        }
        if (cardType == '3'){
            $("#cardPrice").removeClass('hide');
            $("#yy").removeClass('hide');
            $("#discountLa").addClass('hide');
            $("#discount").addClass('hide');
        }
    });
</script>

<!-- jqGrid 公用方法 -->
<script type="application/javascript">

    function style_edit_form(form) {
        //enable datepicker on "sdate" field and switches for "stock" field
        //form.find('input[name=sdate]').datepicker({format:'yyyy-mm-dd' , autoclose:true})

        //form.find('input[name=stock]').addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
        //don't wrap inside a label element, the checkbox value won't be submitted (POST'ed)
        //.addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');


        //update buttons classes
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide();//ui-icon, s-icon
        buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
        buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')

        buttons = form.next().find('.navButton a');
        buttons.find('.ui-icon').hide();
        buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
        buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
    }

    function style_delete_form(form) {
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide();//ui-icon, s-icon
        buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
        buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
    }

    function style_search_filters(form) {
        form.find('.delete-rule').val('X');
        form.find('.add-rule').addClass('btn btn-xs btn-primary');
        form.find('.add-group').addClass('btn btn-xs btn-success');
        form.find('.delete-group').addClass('btn btn-xs btn-danger');
    }

    function style_search_form(form) {
        var dialog = form.closest('.ui-jqdialog');
        var buttons = dialog.find('.EditTable')
        buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
        buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
        buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
    }

    function beforeDeleteCallback(e) {
        var form = $(e[0]);
        if (form.data('styled')) return false;

        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_delete_form(form);
        form.data('styled', true);
    }

    function beforeEditCallback(e) {
        var form = $(e[0]);
        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_edit_form(form);
    }


    //it causes some flicker when reloading or navigating grid
    //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
    //or go back to default browser checkbox styles for the grid
    function styleCheckbox(table) {
        /**
         $(table).find('input:checkbox').addClass('ace')
         .wrap('<label />')
         .after('<span class="lbl align-top" />')


         $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
         .find('input.cbox[type=checkbox]').addClass('ace')
         .wrap('<label />').after('<span class="lbl align-top" />');
         */
    }


    //unlike navButtons icons, action icons in rows seem to be hard-coded
    //you can change them like this in here if you want
    function updateActionIcons(table) {
        /**
         var replacement =
         {
             'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
             'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
             'ui-icon-disk' : 'ace-icon fa fa-check green',
             'ui-icon-cancel' : 'ace-icon fa fa-times red'
         };
         $(table).find('.ui-pg-div span.ui-icon').each(function(){
				var icon = $(this);
				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
				if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
			})
         */
    }

    //replace icons with FontAwesome icons like above
    function updatePagerIcons(table) {
        var replacement =
            {
                'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
                'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
                'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
                'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
            };
        $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
            var icon = $(this);
            var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

            if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
        })
    }

    function enableTooltips(table) {
        $('.navtable .ui-pg-button').tooltip({container: 'body'});
        $(table).find('.ui-pg-div').tooltip({container: 'body'});
    }

    //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

    $(document).one('ajaxloadstart.page', function (e) {
        $.jgrid.gridDestroy(grid_coupontype_selector);
        $('.ui-jqdialog').remove();
    });

    //重新加载数据
    var reload = function () {
//        $(grid_selector).jqGrid('clearGridData');  //清空表格
        $(grid_coupontype_selector).jqGrid('setGridParam',{
            url:"${contextPath}/ktSaleProject/getCardProdListByPage",
            datatype:'json',
//                    postData:param,
            page:1
        }).trigger("reloadGrid"); //重新载入
    }
</script>

<!-- jqGrid加载数据 -->
<script type="text/javascript">
    var scripts = [null, "${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js", "${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js", "${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js", "${contextPath}/static/layer/layer.js","${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js", "${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js", null]
    $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
        jQuery(function ($) {
            jQuery(grid_coupontype_selector).jqGrid({
//                subGrid: true,
                url: "${contextPath}/ktSaleProject/getCardProdListByPage",
                //data: grid_data,
                datatype: "json",
//                datatype : "local",
                mtype: 'POST',
                height: 350,
                colNames : ['编号', '名称', '券类型Type', '券类型', '发放状态', '发放状态', '操作日期', '开始时间','结束时间','','','','','','','','','','','','','','','','','','',''],
                colModel : [
                    {name : 'cardNo',index : 'cardNo',sorttype : ""},
                    {name : 'cardName',index : 'cardName'},
                    {
                        name : 'cardType',index : 'cardType',
//                        align : "right",
                        sorttype : "float",
                        hidden: true,
                    },
                    {
                        name : 'cardTypeName',index : 'cardTypeName',
//                        align : "right",
                        sorttype : "float",
                        formatter: function (c,o,r) {
                            var cardType = r['cardType'];
                            if (cardType == '1')
                                return '折扣卡卷'
                            if (cardType == '2')
                                return '满减卡卷'
                            if (cardType == '3')
                                return '兑换卡卷'
                            return '-'
                        }
                    },
                    {
                        name : 'state',index : 'state',
//                        align : "right",
                        hidden: true,
                        sorttype : "float",
                    },
                    {
                        name : 'stateName',index : 'stateName',
//                        align : "right",
                        sorttype : "float",
                        formatter: function (c, o, r) {
                            var state = r['state'];
                            if (state == '1')
                                return '正常'
                            if (state == '0')
                                return '停止'
                        }
                    },
                    {name : 'createTime',index : 'createTime', sorttype : "date"},
                    {name : 'beginTime',index : 'beginTime',sorttype : "",hidden: true,},
                    {name : 'endTime',index : 'endTime',align : "right",sorttype : "date",hidden: true,},
                    {name : 'dayGetLimit',index : 'dayGetLimit',sorttype : "",hidden: true,},
                    {name : 'cardIcon',index : 'cardIcon',sorttype : "",hidden: true,},
                    {name : 'remark',index : 'remark',sorttype : "",hidden: true,},
                    {name : 'cardCategory',index : 'cardCategory',sorttype : "",hidden: true,},
                    {name : 'id',index : 'id',sorttype : "",hidden: true,},
                    {name : 'beginNoDay',index : 'beginNoDay',sorttype : "",hidden: true,},
                    {name : 'getedQuantity',index : 'getedQuantity',sorttype : "",hidden: true,},
                    {name : 'cardPrice',index : 'cardPrice',sorttype : "",hidden: true,},
                    {name : 'orderUseLimit',index : 'orderUseLimit',sorttype : "",hidden: true,},
                    {name : 'userLimit',index : 'userLimit',sorttype : "",hidden: true,},
                    {name : 'totalQuantity',index : 'totalQuantity',sorttype : "",hidden: true,},
                    {name : 'prodId',index : 'prodId',sorttype : "",hidden: true,},
                    {name : 'cardPwd',index : 'cardPwd',sorttype : "",hidden: true,},
                    {name : 'validDays',index : 'validDays',sorttype : "",hidden: true,},
                    {name : 'createUser',index : 'createUser',sorttype : "",hidden: true,},
                    {name : 'cardData',index : 'cardData',sorttype : "",hidden: true,},
                    {name : 'dayUseLimit',index : 'dayUseLimit',sorttype : "",hidden: true,},
                    {name : 'minUseAmt',index : 'minUseAmt',sorttype : "",hidden: true,},
                    {name : 'operatorTime',index : 'operatorTime',sorttype : "",hidden: true,},
                ],
                rownumbers: true, //自动行数

                autowidth:true,  //宽度自适应
                viewrecords: true,
                rowNum : 10,//一页显示多少条
                rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
                pager : pager_coupontype_selector,//表格页脚的占位符(一般是div)的id
                sortname : 'gmtModifiedStr',//初始化的时候排序的字段
                sortorder : "desc",//排序方式,可选desc,asc
                altRows: true,
                multiselect: true,
                multiboxonly: true,
                loadComplete: function () {
                    var table = this;
                    setTimeout(function () {
                        styleCheckbox(table);
                        updateActionIcons(table);
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                },

                editurl: "${contextPath}/ktSaleProject/saveSaleProject",//nothing is saved
                caption: "卡卷列表",
                jsonReader: {
                    root: "recordList",
                    page: "currentPage",
                    total: "pageCount",
                    records: "recordCount"
                }
//                editurl : ctx+"/RowEditing",
//                caption : "Using events example"
            });

            jQuery(grid_coupontype_selector).jqGrid('navGrid', '#addpager', {
                edit : false,
                add : false,
                del : false,
                search : false
            });

            $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

            $("#jqgh_grid-coupontype-table_rn").html('');
            $("#grid-coupontype-table_rn").css('width', '36px');
//            var mydata = [
//                {id : "1",invdate : "2007-10-01",name : "test",note : "note",amount : "200.00",tax : "10.00",total : "210.00"},
//                {id : "2",invdate : "2007-10-02",name : "test2",note : "note2",amount : "300.00",tax : "20.00",total : "320.00"},
//                {id : "3",invdate : "2007-09-01",name : "test3",note : "note3",amount : "400.00",tax : "30.00",total : "430.00"},
//                {id : "4",invdate : "2007-10-04",name : "test",note : "note",amount : "200.00",tax : "10.00",total : "210.00"},
//                {id : "5",invdate : "2007-10-05",name : "test2",note : "note2",amount : "300.00",tax : "20.00",total : "320.00"},
//                {id : "6",invdate : "2007-09-06",name : "test3",note : "note3",amount : "400.00",tax : "30.00",total : "430.00"},
//                {id : "7",invdate : "2007-10-04",name : "test",note : "note",amount : "200.00",tax : "10.00",total : "210.00"},
//                {id : "8",invdate : "2007-10-03",name : "test2",note : "note2",amount : "300.00",tax : "20.00",total : "320.00"},
//                {id : "9",invdate : "2007-09-01",name : "test3",note : "note3",amount : "400.00",tax : "30.00",total : "430.00"}
//            ];
//            for ( var i = 0; i <= mydata.length; i++){
//                $(grid_coupontype_selector).jqGrid('addRowData', i + 1, mydata[i]);
//            }
        });
    });

</script>

<!-- 模态框 -->
<%--<script type="text/javascript" src="${contextPath}/static/validform/Validform_v5.3.2_min.js"></script>--%>
<script>

//    $("#punishformID").Validform();

    /*** input 实时监控 *****/
    $('#cardNo').bind('input propertychange', function() {
        var cardNo = $(this).val()
        if(!integerVerify(cardNo)){
            $(this).attr('data-content','编号只能输入数字!');
            $("#cardNo").popover('show');
        }else {
            $("#cardNo").popover('hide');
        }
    });

    $('#cardName').bind('input propertychange', function() {
        var cardName = $(this).val()
        if(!chineseVerify(cardName)){
            $(this).attr('data-content','名称只能输入中文字符!');
            $("#cardName").popover('show');
        }else {
            $("#cardName").popover('hide');
        }
    });

    //价格验证
    $('#cardPrice').bind('input propertychange', function() {
        var cardPrice = $(this).val()
        if(!realminVerify(cardPrice)){
            $(this).attr('data-content','价格只能输入正浮点数!');
            $("#cardPrice").popover('show');
        }else {
            $("#cardPrice").popover('hide');
        }
    });
    //折扣率验证
    $('#discount').bind('input propertychange', function() {
        var cardPrice = $(this).val()
        if(!realminVerify(cardPrice)){
            $(this).attr('data-content','折扣率只能输入正浮点数!');
            $("#cardPrice").popover('show');
        }else {
            $("#cardPrice").popover('hide');
        }
    });

    /*********************/

    jQuery(function($){
        //解决模态框背景色越来越深的问题
        $(document).on('show.bs.modal', '.modal', function(event) {
            $(this).appendTo($('body'));
        }).on('shown.bs.modal', '.modal.in', function(event) {
            setModalsAndBackdropsOrder();
        }).on('hidden.bs.modal', '.modal', function(event) {
            setModalsAndBackdropsOrder();
        });

        function setModalsAndBackdropsOrder() {
            var modalZIndex = 1040;
            $('.modal.in').each(function(index) {
                var $modal = $(this);
                modalZIndex++;
                $modal.css('zIndex', modalZIndex);
                $modal.next('.modal-backdrop.in').addClass('hidden').css('zIndex', modalZIndex - 1);
            });
            $('.modal.in:visible:last').focus().next('.modal-backdrop.in').removeClass('hidden');
        }

        //覆盖Modal.prototype的hideModal方法
        $.fn.modal.Constructor.prototype.hideModal = function () {
            var that = this
            this.$element.hide()
            this.backdrop(function () {
                //判断当前页面所有的模态框都已经隐藏了之后body移除.modal-open，即body出现滚动条。
                $('.modal.fade.in').length === 0 && that.$body.removeClass('modal-open')
                that.resetAdjustments()
                that.resetScrollbar()
                that.$element.trigger('hidden.bs.modal')
            })
        }
    });

    /**********  模态框相关设置  **********/
    function centerModals() {
        $('#myModal').each(function(i) {
            var $clone = $(this).clone().css('display','block').appendTo('body');
            var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
            top = top > 0 ? top : 0;
            $clone.remove();
            $(this).find('.modal-content').css("margin-top", top);
        });
    };

    $('#myModal').on('show.bs.modal', centerModals);
    //禁用空白处点击关闭
    $('#myModal').modal({
        backdrop: 'static',
        keyboard: false,//禁止键盘
        show:false
    });
    //页面大小变化是仍然保证模态框水平垂直居中
    $(window).on('resize', centerModals);
    /*************************************/

    $("#addCoupon").click(function () {
        $("#punishformID")[0].reset();
        $("#myModal").modal('show');
    })

    $("#editCoupon").click(function () {
        var id = $(grid_coupontype_selector).jqGrid('getGridParam', 'selrow');
        if (!id) {
            layer.msg("提示：请选择一条信息");
            return;
        }
        var rowData = $(grid_coupontype_selector).jqGrid('getRowData', id);
        $("#punishformID").setForm(rowData);

        $('#myModal').modal('show');
    });

    $("#saveState").click(function () {
        var id = $(grid_coupontype_selector).jqGrid('getGridParam', 'selrow');
        var rowData = $(grid_coupontype_selector).jqGrid('getRowData', id);
        var data = [];
        data.id = id;
        data.state = $("#state1").val();
        console.log(data)
        getObjects(data)
        $('#example1').modal('hide');
    })

</script>